package com.car.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.car.entity.SysUser;
import com.car.mapper.SysUserMapper;
import com.car.mapper.carRoadMapper;
import com.car.pojo.User;
import com.car.pojo.carRoad;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

/**
 * @author VULCAN
 * @create 2020-03-09 17:26
 * @desc
 **/
@Service
public class CarRoadService {

    @Autowired
    private carRoadMapper carRoadMapper;
    @Autowired
    private SysUserMapper userMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    public List<carRoad> getCarRoadList(String id) {
       return carRoadMapper.getRoadList(id);
    }

    public List<carRoad> getRoadcount() {
        return carRoadMapper.getRoadcount();
    }
    public void batchInsert(List<carRoad> carRoads) throws IOException {
        redisTemplate.delete("road");
        String s = JSON.toJSONString(carRoads);
        redisTemplate.opsForValue().set("road",s);
        Object road = redisTemplate.opsForValue().get("road");
        System.out.println("缓存"+road);
        carRoadMapper.batchInsert(carRoads);
    }

    public List<carRoad> getRoadId(String id){
        return carRoadMapper.getRoadId(id);
    }

    public SysUser amin(User user){
        return userMapper.login(user.getUsername(),user.getPassword());
    }
}
